import socket


def get_real_ip():
    try:
        # 获取所有网卡信息
        hostname = socket.gethostname()
        addrs = socket.getaddrinfo(hostname, None)

        # 筛选IPv4地址并排除回环地址
        ip_list = []
        for addr in addrs:
            ip = addr[4][0]
            if ip != '127.0.0.1' and not ip.startswith('::1') and not ip.startswith('fe80:'):
                ip_list.append(ip)

        return ip_list[0] if ip_list else "未找到有效IP"
    except Exception as e:
        return str(e)
